import { SettingType } from '@g/settings';
import { defineStore } from "pinia";
import defaultSettings from '@g/settings'
import Cookies from 'js-cookie'

export const useAppStore = defineStore("app", {
  state: () => {
    return {
      sidebar: { 
        opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
        withoutAnimation: false
      },
      device: 'desktop',
      settings: defaultSettings as SettingType
    };
  },
  getters: {
  },
  actions: {
    // 更改设置内变量值
    updateSettings(data) {

    },
    // 切换侧边栏
    toggleSidebar() {
      this.$patch(state => {
        state.sidebar.opened = !state.sidebar.opened
        state.sidebar.withoutAnimation = false
        if (state.sidebar.opened) {
          Cookies.set('sidebarStatus', 1)
        } else {
          Cookies.set('sidebarStatus', 0)
        }
      })
    },
    closeSideBar(withoutAnimation) {
      this.$patch(state => {
        Cookies.set('sidebarStatus', 0)
        state.sidebar.opened = false
        state.sidebar.withoutAnimation = withoutAnimation
      })
    },
    // 修改设备类型
    toggleDevice(data: 'desktop' | 'mobile') {
      this.$patch(state => state.device = data)
    }
  }
});
